//思路：删除字符串中的所有相邻重复项


import javax.management.remote.rmi._RMIConnection_Stub;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        System.out.println(removeDuplicates("abbaca"));
   }
    public static String removeDuplicates(String s) {
       if(s.length()<=1) return s;
       Stack<Character> st=new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c=s.charAt(i);
            if(st.empty()){
                st.push(c);
            } else{
                char c1=st.pop();
                if(c1!=c){
                    st.push(c1);
                    st.push(c);
                }
            }
        }
        String re="";
        while(!st.empty()){
            re=st.pop()+re;
        }
        return re;

    }
}














